﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

using FluentValidation;
using CashFlow.Web.Models;
using CashFlow.Web.Common;

namespace CashFlow.Web.Validator
{
    public class UpdateUserAccountInfoModelValidator
        : AbstractValidator<UpdateUserAccountInfoModel>
    {
        public UpdateUserAccountInfoModelValidator()
        {
            CascadeMode = CascadeMode.Stop;
            RuleFor(x => x.BankAccountName).Must(x =>
            {
                if (!string.IsNullOrEmpty(x))
                {
                    return RegExpTool.IsBankAccountName(x);
                }
                return true;
            }).WithMessage("开户行账户名长度不超过10！");
            RuleFor(x => x.BankName).Must(x =>
            {
                if (!string.IsNullOrEmpty(x))
                {
                    return x.Length <= 50;
                }
                return true;
            }).WithMessage("开户行长度不超过50！");
            RuleFor(x => x.BankCardNo).Must(x =>
            {
                if (!string.IsNullOrEmpty(x))
                {
                    return x.Length <= 50;
                }
                return true;
            }).WithMessage("银行卡卡号不超过30！");
            RuleFor(x => x.WechatPath).Must(x =>
            {
                if (!string.IsNullOrEmpty(x))
                {
                    return RegExpTool.IsImagePath(x);
                }
                return true;
            }).WithMessage("微信收款码图片path不合法");
            RuleFor(x => x.AlipayPath).Must(x =>
            {
                if (!string.IsNullOrEmpty(x))
                {
                    return RegExpTool.IsImagePath(x);
                }
                return true;
            }).WithMessage("支付宝收款码图片path不合法");
        }
    }
}